<template>
  <div>
    <van-nav-bar title="我的收藏" left-arrow @click-left="onClickLeft" />
    <van-swipe-cell v-for="(item, index) in favoriteList" :key="index">
      <allSingle :post="item"></allSingle>
      <template #right>
        <van-button
          @click="postStarFn(item.id, index)"
          square
          text="删除"
          type="danger"
          class="delete-button"
        />
      </template>
    </van-swipe-cell>
  </div>
</template>

<script>
import allSingle from "@/components/allSingle.vue";
import { userStar, postStar } from "@/apis/get.js";
export default {
  data() {
    return {
      favoriteList: {},
    };
  },
  created() {
    userStar().then((res) => {
      // console.log(15, res);
      this.favoriteList = res.data.data;
    });
  },
  components: {
    allSingle,
  },
  methods: {
    onClickLeft() {
      this.$router.push({
        path: "personal",
      });
    },
    postStarFn(id, index) {
      postStar(id).then((res) => {
        // console.log(res);
        this.$toast(res.data.message);
        this.favoriteList.splice(index, 1);
      });
    },
  },
};
</script>

<style lang="less" scoped>
.van-button {
  height: 100%;
}
</style>